   
/*  Colluding Against Workers -- Reduced form evidence
	Delabastita & Rubens
--------------------------------*/

clear
set more off
cd "$station"
 
use ./data/temp/data_pf, clear 
set matsize 10000
 
** Collusion indicators
sum dunion
bys mineid: egen e_union = max(dunion)
bys mineid: egen e_car = max(dcar)

** Fact 1: Labor productivity grew faster than wages

preserve
 gen w = expenses_l
 collapse(sum) emp w q rev, by(yr)
 gen uw = w/emp
 gen p = rev/q
 
 gen lemp = log(emp)
 gen lq = log(q)
 gen lp = log(p)
 gen luw = log(uw)
 twoway connect luw lp yr
 
 gen lqemp = log(q/emp)
 
 ***twoway connect lqemp yr || connect luw yr, yaxis(2) graphregion(color(white))
twoway (connect luw yr, yaxis(1) ytitle("log(Daily wage)" "(in 1910BEF)", axis(1) /*size(large)*/) lwidth(medium) msize(medium) mcolor(white) mlcolor(navy) ylabel(,angle(horizontal) axis(1) /*labsize(large)*/) lcolor(navy)) ///
(connect lqemp yr, yaxis(2) lwidth(medium) msize(medsmall) msymbol(diamond) mcolor(white) mlcolor(maroon) ytitle("log(Output per worker)"  , axis(2) /*size(large)*/)   ylabel(,angle(horizontal) axis(2) /*labsize(large)*/) lcolor(maroon ) lpattern(solid)) ///
, graphregion(color(white)) xline(1898, lpattern(longdash))  xscale(titlegap(*5)) xtitle("Year", /*size(large)*/) legend(order(1 "log(Daily wage)" 2 "log(Output per worker)") /*size(large)*/ col(2)) xlabel(, /*labsize(large)*/) 

 graph export ./output/fig/fig_lqemp.pdf, replace
restore
  
 * Revenue and cost share of labor
 
 bys yr: egen revtot = sum(rev)
 bys yr: egen wltot = sum(wl)
 bys yr: egen wmtot = sum(wm)
 bys yr: egen wktot = sum(winv)
bys yr: egen avlshare = mean(wl/rev)
bys yr: egen medlshare = median(wl/rev)
gen costtot = wktot+wmtot+wltot
 gen aglshare = wltot/revtot
 gen aglcshare = wltot/costtot
 gen agmcshare = wmtot/costtot
 bys yr: egen medlcshare = median(wl/(wl+winv+wm))
 bys yr: egen medmcshare = median(wm/(wl+winv+wm))
 
 
 replace medlcshare = medlcshare*100
 replace aglcshare = aglcshare*100
 sort yr
 twoway (connect medlcshare     yr, yaxis(1) ytitle("Cost share of labor (%)", axis(1) /*size(large)*/) lwidth(medium) msize(medium) mcolor(white) mlcolor(navy) ylabel(,angle(horizontal) axis(1) /*labsize(large)*/) lcolor(navy)) ///
(connect aglcshare yr, yaxis(1) lwidth(medium) msize(medsmall) msymbol(diamond) mcolor(white) mlcolor(maroon)  /*size(large)*/)     ///
, graphregion(color(white))  xline(1897, lpattern(longdash))  xscale(titlegap(*5)) xtitle("Year", /*size(large)*/) legend(label(1 "Median") label( 2 "Weighted average" ) /*size(large)*/ col(2)) xlabel(, /*labsize(large)*/) 
    graph export ./output/fig/fig_csl.pdf, replace

	
  twoway (connect medmcshare     yr, yaxis(1) ytitle("Cost share of materials (%)", axis(1) /*size(large)*/) lwidth(medium) msize(medium) mcolor(white) mlcolor(navy) ylabel(,angle(horizontal) axis(1) /*labsize(large)*/) lcolor(navy)) ///
(connect agmcshare yr, yaxis(1) lwidth(medium) msize(medsmall) msymbol(diamond) mcolor(white) mlcolor(maroon)  /*size(large)*/)     ///
, graphregion(color(white))  xscale(titlegap(*5)) xtitle("Year", /*size(large)*/) legend(label(1 "Median") label( 2 "Weighted average" ) /*size(large)*/ col(2)) xlabel(, /*labsize(large)*/) 
   
* graph export ./output/fig/fig_csm.pdf, replace

 /* 
* Fact 2: No input price variation even across provinces.
*/
 * Fact 3: Cartel led to coal price increase relatively to (exogenous) import price

gen imp_p = degreve_imp_pq*1000 / degreve_imp_q 
bys yr dcar: egen avpc = mean(p)
sort yr
label var yr "Year"
 
 tab dcar if yr==1898
 preserve
 bys dcar yr: egen qcar = sum(q)
 gen sqcar = qcar/qyr
 bys dcar: sum sqcar if yr==1898
 restore
  
 
twoway  connect avpc yr if dcar==0 , legend(label(1 "Cartel dissenters")) lwidth(medium) msize(medium) mcolor(white) mlcolor(navy) ylabel(,angle(horizontal) axis(1) /*labsize(large)*/) lcolor(navy) ///
|| connect avpc yr if dcar==1 , legend(label(2 "Cartel participants")) lwidth(medium) msize(medsmall) msymbol(diamond) mcolor(white) mlcolor(maroon) ///
|| connect imp_p yr, legend(label(3 "Import price")) lwidth(medium) msize(medsmall) msymbol(diamond) mcolor(white) mlcolor(maroon)   ///
	xline(1898, lwidth(medthick) lpattern(longdash) lcolor(orange_red)) lwidth(medium) msize(medsmall) msymbol(square) mcolor(white) mlcolor(green) ///
	graphregion(color(white))  ytitle("Coal price" "(in BEF/ton)" ) legend(col(3)) xscale(titlegap(*5))
 
	
 	graph export ./output/fig/fig_cartel.pdf, replace

 
	

* Fact 4: mechanization


**Investments
drop totwinv
bys yr: egen totwinv = sum(winv)
sort yr
replace totwinv = totwinv/1000000
replace totwinv = . if totwinv==0
label variable totwinv "Investment (Million BEF)"


twoway connect totwinv yr , graphregion(color(white)) xscale(titlegap(*5)) xtitle("Year") ytitle("Investments" "(in Millions 1910BEF)") ylabel(,angle(horizontal))  lcolor(navy) lwidth(medium) msize(medium) mcolor(white) mlcolor(navy) 

 graph export ./output/fig/fig_winv.pdf, replace



**Mechanization (kcut kloc kven kot)
preserve
collapse (sum) kcut kloc kven kot q emp, by(yr)
drop if yr > 1900
foreach var of varlist kven kot kloc kcut{
replace `var' = . if `var'==0
gen `var'emp = `var'/emp
}

twoway connect kcutemp klocemp kvenemp kotemp yr, graphregion(color(white))legend(order(1 "Hauling" 2 "Water pumping" 3 "Ventilation" 4 "Other") col(2) ) xtitle("Year", ) ytitle("Horsepower/labor", ) xscale(titlegap(*5)) ylabel(,angle(horizontal) ) ///
 xscale(range(1840 1920))	xlabel(1840(20)1920) lpattern(solid solid solid solid) lwidth(medium medium medium medium) msymbol(circle diamond square triangle) msize(medium msmall medium medium) mcolor(white white white white) mlcolor(navy maroon green gold) lcolor(navy maroon green gold) xlabel(, ) 
 graph export ./output/fig/fig_mech.pdf, replace
restore

 
* Fact 5: no adjustment costs: look how fast employment and materials reacted to price jump

bys yr: egen agempyr = sum(emp)
bys yr: egen wmyr = sum(wm)
bys yr: egen avempyr = mean(emp)
bys yr: egen avuwlyr = mean(wl/emp)
bys yr: egen medempyr = median(emp)
gen degreve_imp_p = degreve_imp_pq/degreve_imp_q 
bys yr: egen agqyr = sum(q)
bys yr: egen agrevyr = sum(rev)
gen agpyr = agrevyr/agqyr  
bys yr: egen agwlyr = sum(wl)
bys yr: egen medwlyr = median(wl)
bys yr: egen meduwlyr = median(wl/emp)
bys yr: egen medwmyr = median(wm)
bys yr: egen medwinvyr = median(winv)

label variable degreve_imp_p "Import price of coal"
label variable medwlyr "Labor expenditure"
label variable medwmyr "Intermediate input expenditure"
label variable medwinvyr "Capital investment"
label variable meduwlyr "Wage"

* impulse-response graphs:  
preserve
keep if yr<1880 & yr>1865

twoway connect  degreve_imp_p yr, lwidth(medium) msize(medium) mcolor(white) mlcolor(navy) msymbol(circle) yaxis(1) ylabel(,angle(horizontal)) yscale(titlegap(*2))|| ///
		connect meduwlyr yr , lwidth(medium) msize(medsmall) msymbol(diamond) mcolor(white) mlcolor(maroon) yaxis(2) ylabel(,angle(horizontal) axis(2)) xline(1870, lwidth(medthick) lpattern(longdash) lcolor(orange_red)) ///
		graphregion(color(white)) xscale(titlegap(*5)) legend(col(2))  
* graph export ./output/fig/fig_impresp_uw.pdf, replace 

 twoway connect  degreve_imp_p yr, lwidth(medium) msize(medium) mcolor(white) mlcolor(navy) msymbol(circle) yaxis(1) ylabel(,angle(horizontal)) yscale(titlegap(*2))|| ///
		connect medempyr yr , lwidth(medium) msize(medsmall) msymbol(diamond) mcolor(white) mlcolor(maroon) yaxis(2) ylabel(,angle(horizontal) axis(2)) xline(1871, lwidth(medthick) lpattern(longdash) lcolor(orange_red)) ///
		graphregion(color(white)) xscale(titlegap(*5)) legend(col(2))  
* graph export ./output/fig/fig_impresp_emp.pdf, replace 

 
twoway connect  degreve_imp_p yr, lwidth(medium) msize(medium) mcolor(white) mlcolor(navy) msymbol(circle) yaxis(1) ylabel(,angle(horizontal)) yscale(titlegap(*2))|| ///
		connect medwlyr yr , lwidth(medium) msize(medsmall) msymbol(diamond) mcolor(white) mlcolor(maroon) yaxis(2) ylabel(,angle(horizontal) axis(2)) xline(1871, lwidth(medthick) lpattern(longdash) lcolor(orange_red)) ///
		graphregion(color(white)) xscale(titlegap(*5)) legend(col(2))  
 graph export ./output/fig/fig_impresp_l.pdf, replace 
twoway connect  degreve_imp_p yr, lwidth(medium) msize(medium) mcolor(white) mlcolor(navy) msymbol(circle) yaxis(1) ylabel(,angle(horizontal)) yscale(titlegap(*2)) || ///
		connect medwmyr yr , lwidth(medium) msize(medsmall) msymbol(diamond) mcolor(white) mlcolor(maroon) yaxis(2)  ylabel(,angle(horizontal) axis(2)) xline(1871, lwidth(medthick) lpattern(longdash) lcolor(orange_red)) ///
		graphregion(color(white)) xscale(titlegap(*5)) legend(col(2)) 
 graph export ./output/fig/fig_impresp_m.pdf, replace
twoway connect  degreve_imp_p yr, lwidth(medium) msize(medium) mcolor(white) mlcolor(navy) msymbol(circle) yaxis(1) ylabel(,angle(horizontal)) yscale(titlegap(*2)) || ///
		connect medwinvyr yr , lwidth(medium) msize(medsmall) msymbol(diamond) mcolor(white) mlcolor(maroon) yaxis(2)  ylabel(,angle(horizontal) axis(2)) xline(1871, lwidth(medthick) lpattern(longdash) lcolor(orange_red)) ///
		graphregion(color(white)) xscale(titlegap(*5)) legend(col(2))  
 graph export ./output/fig/fig_impresp_k.pdf, replace  
*twoway connect  degreve_imp_p yr || connect agwlyr yr , yaxis(2)
restore


 
twoway connect cpi yr, xline(1871)	// it's not inflation.
 